package com.gcxy.exception.handler;

import com.gcxy.core.R;
import com.gcxy.enums.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.function.Supplier;

/**
 * Copyright (C), 2024-2024, BUG闭退！
 * Author: Huang先森
 * Date: 2024/7/22 13:18
 * FileName: BaseThrowExceptionHandler
 * Description: 异常底层执行逻辑
 */

@Slf4j
public class BaseThrowExceptionHandler {
    public static R exception(Throwable throwable, ResultCodeEnum resultCodeEnum, Supplier<String> supplier) {
        try {
            return R.Failed(resultCodeEnum.getCode(), supplier.get());
        } catch (Exception e) {
            log.error("UnKnown exception: ", throwable);
            return R.Failed(throwable.getMessage());
        }
    }
}
